﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RealtorsPortal.Business_Logic_Layer;

namespace RealtorsPortal.AdminCP
{
    public partial class PayAdvertisement : System.Web.UI.Page
    {
        AdvertisementsDAL avdv = new AdvertisementsDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.LoadAndBindData();
            }
        }

        private void LoadAndBindData()
        {
            grvUnpaidAds.DataSource = avdv.GetUnPaidAdsDataTable();
            grvUnpaidAds.DataBind();
        }


        protected void grvManageMyAdver_RowCommand(object sender, GridViewCommandEventArgs e)
        {
             if (e.CommandName == "BrowseComponent")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string AdvId = grvUnpaidAds.DataKeys[index].Value.ToString();
                //Response.Redirect("~/AdminCP/AdvertisementDetails.aspx/ID=" + AdvId);
                Server.Transfer("~/AdminCP/AdvertisementDetails.aspx?ID=" + AdvId);
            }
            else if (e.CommandName == "PayComponent")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string AdvId = grvUnpaidAds.DataKeys[index].Value.ToString();
                ViewState["AdId"] = AdvId;
                pnlAdsList.Visible = false;
                pnlPayment.Visible = true;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int advId = int.Parse(ViewState["AdId"].ToString());
            AdvertisementsDAL advd = new AdvertisementsDAL();
            if (advd.PayAdvertisement(advId))
            {
                lblStatus.Text = " Pay successful! Thank you for use system!";
                this.LoadAndBindData();
                pnlAdsList.Visible = true;
                pnlPayment.Visible = false;
            }
        }
    }
}